package com.jiunuan.live.core.server.rpc;

import com.jiunuan.live.core.server.service.IRouterHandlerService;
import com.jiunuan.live.im.core.server.interfaces.rpc.IRouterHandlerRpc;
import com.jiunuan.live.im.dto.ImMsgBody;
import jakarta.annotation.Resource;
import org.apache.dubbo.config.annotation.DubboService;

import java.util.List;

/**
 * @Author: JiuNuan
 * @CreateTime: 2024-08-16 11:40
 * @Description:
 */
@DubboService
public class RouterHandlerRpcImpl implements IRouterHandlerRpc {
    @Resource
    private IRouterHandlerService routerHandlerService;
    /**
     * 按照用户id进行消息的发送
     *
     * @param imMsgBody
     */
    @Override
    public void sendMsg(ImMsgBody imMsgBody) {
        routerHandlerService.onReceive(imMsgBody);
    }

    /**
     * 支持批量发送消息
     *
     * @param imMsgBodyList 消息体列表，包含需要批量发送的消息
     */
    @Override
    public void batchSendMsg(List<ImMsgBody> imMsgBodyList) {
        // 对消息体列表进行遍历，逐一处理消息发送
        imMsgBodyList.forEach(imMsgBody -> {
            // 调用路由处理服务的onReceive方法来处理每个消息体
            routerHandlerService.onReceive(imMsgBody);
        });
    }

}
